package com.ruoyi.dp.service.impl;

import com.ruoyi.dp.domain.DpSafeOperation;
import com.ruoyi.dp.mapper.DpSafeOperationMapper;
import com.ruoyi.dp.service.IDpSafeOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class DpSafeOperationServiceImpl implements IDpSafeOperationService {

    @Autowired
    private DpSafeOperationMapper dpSafeOperationMapper;

    @Value("${safeOperation.models}")
    private String models;

    @Value("${safeOperation.targets}")
    private String targets;

    @Override
    public Map<String,Object> selectDpSafeOperatioinList() {
        // 分割 models 和 targets
        String[] modelArray = models.split(",");
        String[] targetArray = targets.split(",");
        Map<String,Object>  modelMap = new HashMap<String,Object>();
        for (String model : modelArray) {
            Map<String,List<DpSafeOperation>>  targetMap = new HashMap<String,List<DpSafeOperation>>();
            for (String target: targetArray){
                DpSafeOperation dpsafe = new DpSafeOperation();
                dpsafe.setModel(model);
                dpsafe.setTarget(target);
                if (target.equals("一般事件万时率")){
                    dpsafe.setStatisticsObj(null);
                }else{
                    dpsafe.setStatisticsObj(model);
                }
                targetMap.put(target,dpSafeOperationMapper.selectDpSafeOperatioinList(dpsafe));
            }
            modelMap.put(model,targetMap);
        }
        return modelMap;
    }

    @Override
    public DpSafeOperation selectDpSafeOperatioinById(Long id) {
        return dpSafeOperationMapper.selectDpSafeOperatioinById(id);
    }

    @Override
    public int insertDpSafeOperatioin(DpSafeOperation dpSafeOperation) {
        return dpSafeOperationMapper.insertDpSafeOperatioin(dpSafeOperation);
    }

    @Override
    public int updateDpSafeOperatioin(DpSafeOperation dpSafeOperation) {
        return dpSafeOperationMapper.updateDpSafeOperatioin(dpSafeOperation);
    }

    @Override
    public int deleteDpSafeOperatioinById(Long id) {
        return dpSafeOperationMapper.deleteDpSafeOperatioinById(id);
    }
}
